// Copyright 2023 Huawei Cloud Computing Technology Co., Ltd.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
//     http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

#ifndef HUAWEICLOUD_CLOUDPHONEACCESS_ENGINE_CAEVIRTUALDEVICECONFIG_H
#define HUAWEICLOUD_CLOUDPHONEACCESS_ENGINE_CAEVIRTUALDEVICECONFIG_H

#include <string>
#include <error.h>
#include <sys/endian.h>
#include "../cae_common/CaeLogConfig.h"
#include "../cae_dataPipe/CaePipeData.h"

const std::string CAMERA_PARAMETERS = "preview-size=640x480;" \
            "video-size=1920x1080;" \
            "preferred-preview-size-for-video=1280x720;" \
            "preview-size-values=1280x720,640x480,480x320,352x288;" \
            "video-size-values=1280x720,640x480,480x320,352x288;"  \
            "preview-format=yuv420sp;" \
            "preview-format-values=yuv420sp;" \
            "preview-frame-rate=30;" \
            "preview-fps-range=10,30;" \
            "preview-fps-range-values=(15000,15000),(20000,20000),(24000,24000),(7000,30000),(30000,30000),(10000,30000);" \
            "preview-frame-rate-values=15,20,24,30;" \
            "picture-size=1280x720;" \
            "picture-size-values=640x360,1920x1080,1280x720;" \
            "picture-format=jpeg;" \
            "picture-format-values=jpeg;" \
            "jpeg-thumbnail-width=320;" \
            "jpeg-thumbnail-height=240;" \
            "jpeg-thumbnail-size-values=0x0,176x144,240x144,256x144,240x160,256x154,240x240,320x240;" \
            "jpeg-thumbnail-quality=90;" \
            "jpeg-quality=90;" \
            "rotation=0;" \
            "whitebalance=auto;" \
            "whitebalance-values=auto,incandescent,fluorescent,warm-fluorescent,daylight,cloudy-daylight,twilight,shade,;" \
            "effect=none;" \
            "effect-values=none,mono,negative,solarize,sepia,posterize,whiteboard,blackboard,aqua;" \
            "antibanding=auto;" \
            "antibanding-values=off,60hz,50hz,auto;" \
            "scene-mode=auto;" \
            "scene-mode-values=auto,landscape,snow,beach,sunset,night,portrait,sports,steadyphoto,candlelight,fireworks,party,night-portrait,theatre,action,hdr;" \
            "flash-mode=off;" \
            "flash-mode-values=off,auto,on,torch,red-eye;" \
            "focus-mode=auto;" \
            "focus-mode-values=infinity,auto,macro,continuous-video,continuous-picture;" \
            "max-num-focus-areas=1;" \
            "focus-areas=(-300,-300,300,300,1);" \
            "focal-length=3.82;" \
            "horizontal-view-angle=66.8245;" \
            "vertical-view-angle=52.5286;" \
            "zoom=0;" \
            "zoom-supported=false;" \
            "smooth-zoom-supported=false;" \
            "focus-distances=Infinity,Infinity,Infinity;" \
            "max-num-detected-faces-hw=10;" \
            "max-num-detected-faces-sw=0;" \
            "video-frame-format=android-opaque;" \
            "recording-hint=false;" \
            "video-snapshot-supported=true;" \
            "video-stabilization=false;" \
            "video-stabilization-supported=true";

enum CameraOptionCmd {
    OPT_CAMERA_GET_PARAM_REQ = 0x1,
    OPT_CAMERA_SET_PARAM_REQ = 0x2,
    OPT_CAMERA_GET_INFO_REQ = 0x3,
    OPT_CAMERA_START_PREVIEW_REQ = 0x4,
    OPT_CAMERA_STOP_PREVIEW_REQ = 0x5,
    OPT_CAMERA_IS_USE_H264_REQ = 0x6,
    OPT_CAMERA_GET_SIZE_REQ = 0x7,
    OPT_CAMERA_VIDEO_FRAME_REQ = 0x8,

    OPT_CAMERA_GET_PARAM_RSP = 0x1001,
    OPT_CAMERA_SET_PARAM_RSP = 0x1002,
    OPT_CAMERA_GET_INFO_RSP = 0x1003,
    OPT_CAMERA_START_PREVIEW_RSP = 0x1004,
    OPT_CAMERA_STOP_PREVIEW_RSP = 0x1005,
    OPT_CAMERA_IS_USE_H264_RSP = 0x1006,
    OPT_CAMERA_GET_SIZE_RSP = 0x1007,
    OPT_CAMERA_CMD_MAX
};

enum MicrophoneOptionCmd {
    OPT_MIC_START_RECORD_REQ = 0x1,
    OPT_MIC_STOP_RECORD_REQ = 0x2,
    OPT_MIC_SET_PARAM_REQ = 0x3,
    OPT_MIC_AUDIO_FRAME = 0x10,

    OPT_MIC_START_RECORD_RSP = 0x1001,
    OPT_MIC_STOP_RECORD_RSP = 0x1002,
    OPT_MIC_SET_PARAM_RSP = 0x1003,
    OPT_MIC_CMD_MAX
};

struct MSG_HEADER {
    uint16_t version;
    uint16_t optType;
    uint16_t devType;
    uint16_t devId;
    uint32_t len;
    uint16_t nextProto;
    uint16_t hopLimits;
}__attribute__((packed));

struct RSP_MSG_HEADER {
    uint16_t version;
    uint16_t optType;
    uint16_t devType;
    uint16_t devId;
    uint32_t len;
    uint16_t nextProto = htons(0x00);
    uint16_t hopLimits = htons(0x00);
    uint16_t result;
}__attribute__((packed));

class CaeVirtualDeviceConfig {
public:
    static uint32_t GetLocalCameraStreamInjectFileType();

    static uint32_t GetLocalMicrophoneStreamInjectFileType();

    static const char * &GetCameraStreamH264FilePath();

    static const char * &GetCameraStreamYuvFilePath();

    static const char * &GetCameraStreamJpegFilePath();

    static const char *GetMicrophoneStreamPcmFilePath();

    static bool IsOpenCamera();

    static void SetOpenCameraFlag(bool isOpenCamera, MSG_HEADER *header, uint8_t *data, CaePipeData *pipeData);

    static bool IsOpenMicrophone();

    static void SetOpenMicrophoneFlag(bool isOpenMicrophone, MSG_HEADER *header, uint8_t *data, CaePipeData *pipeData);

    static MSG_HEADER *GetCameraTmpHeader();

    static uint8_t *GetCameraTmpData();

    static CaePipeData *GetCameraTmpPipeData();

    static MSG_HEADER *GetMicrophoneTmpHeader();

    static uint8_t *GetMicrophoneTmpData();

    static CaePipeData *GetMicrophoneTmpPipeData();

private:
    static bool isOpenCameraFlag;
    static bool isOpenMicrophoneFlag;
    static MSG_HEADER *cameraTmpHeader;
    static uint8_t *cameraTmpData;
    static CaePipeData *cameraTmpPipeData;
    static MSG_HEADER *microphoneTmpHeader;
    static uint8_t *microphoneTmpData;
    static CaePipeData *microphoneTmpPipeData;
};


#endif //HUAWEICLOUD_CLOUDPHONEACCESS_ENGINE_CAEVIRTUALDEVICECONFIG_H
